package com.enjoyor.soa.traffic.rest.tsms.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.tsms.RouteInfoDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.ISchemeActionConsumeService;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Auth
@RestController
@RequestMapping({ "/scheme" }) 
@Api("SchemeActionController相关api")
@CrossOrigin
public class SchemeActionController {

	@Autowired
	ISchemeActionConsumeService iSchemeActionDubboConsumeService;	
	/**
	 * 实际运行，推送服务
	 * 
	 * @return
	 */
	@GetMapping(value = { "/getActionPush" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("监测执行")
	@ApiImplicitParams({ @ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", dataType = "string"),
		//@ApiImplicitParam(name = "browserId", value = "浏览器id", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "positionDeviceId", value = "定位设备id", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "state", value = "状态(start/stop/reset/change/position)", paramType = "query", dataType = "String")})
	public void getPushServer(
			@RequestParam(defaultValue = "") String routeId,
			@RequestParam(defaultValue = "")String executeTaskId, String state,String positionDeviceId,
			HttpServletRequest request) { 
		String personName = ((UserDto) request.getAttribute("currentUser")).getPersonName();
		iSchemeActionDubboConsumeService.getPushServer(routeId, executeTaskId, state, positionDeviceId, personName);
	}
	
	/**
	 * 方案执行--切换线路，
	 * 
	 * @return
	 */
	@GetMapping(value = { "/getActionChangeRoute" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("方案执行--切换线路")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "routeId", value = "切换线路编号", paramType = "query", dataType = "string")})
	public void getActionChangeRoute(
			@RequestParam(defaultValue = "") String routeId,
			@RequestParam(defaultValue = "") String executeTaskId,
			HttpServletRequest request) { 
		String personName = ((UserDto) request.getAttribute("currentUser")).getPersonName();
		String state = "change";
		iSchemeActionDubboConsumeService.getPushServer(routeId, executeTaskId, state, null, personName);
	}
	
	/**
	 * 方案执行--制定应急线路，
	 * 
	 * @return
	 */
	@GetMapping(value = { "/getActionFastRoute" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("方案执行--制定应急线路")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "routeId", value = "原线路编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "newGeoStr", value = "应急线路信息", paramType = "query", dataType = "String")})
	public ResultPojo getActionFastRoute(
			@RequestParam(defaultValue = "") String executeTaskId,
			@RequestParam(defaultValue = "") String routeId,
			@RequestParam(defaultValue = "") String newGeoStr,
			HttpServletRequest request) { 
		String personName = ((UserDto) request.getAttribute("currentUser")).getPersonName();
		return iSchemeActionDubboConsumeService.changeFastRoute(executeTaskId, routeId, newGeoStr, personName);
	}
	
	/**
	 * 获取方案执行线程
	 * @return
	 */
	@GetMapping(value = { "/getActionDataPoolList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("获取方案执行线程")
	public ResultPojo getActionDataPoolList(HttpServletRequest request) { 
		ResultPojo resultPojo = iSchemeActionDubboConsumeService.getActionDataPoolList();
		return resultPojo;
	}
	/**
	 * 清除方案执行线程，
	 * @return
	 */
	@GetMapping(value = { "/clearActionDataPool" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("清除方案执行线程")
	@ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", dataType = "string")
	public ResultPojo clearActionDataPool(
			@RequestParam(defaultValue = "") String executeTaskId,
			HttpServletRequest request) { 
		ResultPojo resultPojo = iSchemeActionDubboConsumeService.clearActionDataPool(executeTaskId);
		return resultPojo;
	}
	/**
	 * 获取方案预演线程
	 * @return
	 */
	@GetMapping(value = { "/getRehearseDataPoolList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("获取方案预演线程")
	public ResultPojo getRehearseDataPoolList(HttpServletRequest request) { 
		ResultPojo resultPojo = iSchemeActionDubboConsumeService.getRehearseDataPoolList();
		return resultPojo;
	}
	/**
	 * 清除方案预演线程，
	 * @return
	 */
	@GetMapping(value = { "/clearRehearseDataPool" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("清除方案预演线程")
	@ApiImplicitParam(name = "threadName", value = "线路名称", paramType = "query", dataType = "string")
	public ResultPojo clearRehearseDataPool(
			@RequestParam(defaultValue = "") String threadName,
			HttpServletRequest request) { 
		ResultPojo resultPojo = iSchemeActionDubboConsumeService.clearRehearseDataPool(threadName);
		return resultPojo;
	}
	
}
